/**   
 * @title: AgainstTeamListLocalFilter.java 
 * @package com.esun.rabbit2.viewer.mainact.lotteryhallact.sportterybasketballapg 
 * @description: 将从服务器获得的比赛信息列表按用户设置的条件进行筛选
 * @author: liugan   
 * @date: 2012-3-12 下午17:50  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.sportterybasketballapg;

import java.util.ArrayList;
import java.util.Hashtable;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.sportterybasketball.SportteryBasketballAgainstInfo;

/**
 * @className: AgainstTeamListLocalFilter
 * @description:将从服务器获得的信息列表按用户设置的条件进行筛选,设计成单例
 * @author: liugan
 * @date: 2012-3-12 下午17:50
 * 
 */
public class AgainstTeamListLocalFilter {

	/**
	 * @field:instance
	 * @description: 该类的唯一实例
	 */
	private static AgainstTeamListLocalFilter instance;

	/**
	 * @title:AgainstTeamListLocalFilter
	 * @description:私有的构造方法
	 */
	private AgainstTeamListLocalFilter() {

	}

	/**
	 * @title:getInstance
	 * @description: 获得该类唯一的实例
	 * @return AgainstTeamListLocalFilter
	 */
	public static synchronized AgainstTeamListLocalFilter getInstance() {
		if (instance == null) {
			instance = new AgainstTeamListLocalFilter();
		}
		return instance;
	}


	/**
	 * @title:doFilter4JCLQSF
	 * @description:为竞彩篮球胜负彩种过滤比赛信息
	 * @param againstList
	 *            比赛列表
	 * @param peilvType
	 *            赔率类型
	 * @param leagueNameList
	 *            用户选择了的联赛类型列表
	 * @param isAll
	 *            是否全选
	 */
	public void doFilter4JCLQSF(ArrayList<Hashtable<String, Object>> againstList, int peilvType, ArrayList<String> leagueNameList, boolean isAll) {
		Hashtable<String, Object> againstInfo;
		// 通过遍历设置标志位来进行过滤
		for (int i = 0; i < againstList.size(); i++) {
			againstInfo = againstList.get(i);

			if ((Boolean) againstInfo.get(Key.KEY_IS_TITLE)) {// 标题的分支
				againstInfo.put(Key.KEY_IS_SHOW, true);
			} else if ((isRightLeague((SportteryBasketballAgainstInfo) againstInfo.get(Key.KEY_INFO), leagueNameList) || isAll)
					&& isRightPeilv((SportteryBasketballAgainstInfo) againstInfo.get(Key.KEY_INFO), peilvType)) {
				// 用户希望显示的对阵信息分支
				againstInfo.put(Key.KEY_IS_SHOW, true);
			} else {// 用户不需要的对阵信息分支
				againstInfo.put(Key.KEY_IS_SHOW, false);
				againstInfo.put(Key.KEY_IS_ACTIVE, false);
				againstInfo.put(Key.KEY_W, false);
				againstInfo.put(Key.KEY_L, false);
				againstInfo.put(Key.KEY_IS_DAN, false);
			}
		}
	}

	/**
	 * @title:isRightPeilv
	 * @description:判断一个对阵是否有用户希望的赔率
	 * @param sportteryBasketballAgainstInfo
	 *            一场篮球比赛的详细信息
	 * @param peilvType
	 *            赔率类型
	 * @return 该场比赛是否达到期望赔率
	 */
	// 0:全部,1:高命中区间,2:实力赔率区间,3:高额回报区间
	private boolean isRightPeilv(SportteryBasketballAgainstInfo sportteryBasketballAgainstInfo, int peilvType) {
		boolean b = false;
		double w = Double.parseDouble(sportteryBasketballAgainstInfo.getWin());
		double l = Double.parseDouble(sportteryBasketballAgainstInfo.getLost());
		if (peilvType == 0) {// 用户指定的赔率为全部时
			b = true;
		} else if (peilvType == 1) {// 为高命中区间时
			if (w < 1.5 || l < 1.5) {
				b = true;
			}
		} else if (peilvType == 2) {// 为实力赔率区间时
			if ((w >= 1.5 && w < 2) || (l >= 1.5 && l < 2)) {
				b = true;
			}
		} else if (peilvType == 3) {// 为高额回报区间时
			if (w >= 2 || l >= 2) {
				b = true;
			}
		}
		return b;
	}

	/**
	 * @title:isRightLeague
	 * @description:判断一场比赛是否是用户选择的联赛中的比赛
	 * @param sportteryBasketballAgainstInfo
	 *            一场比赛的详细信息
	 * @param leagueNameList
	 *            用户选择的所有联赛
	 * @return 该场比赛是否符合条件
	 */

	private boolean isRightLeague(SportteryBasketballAgainstInfo sportteryBasketballAgainstInfo, ArrayList<String> leagueNameList) {
		boolean b = false;
		String strItmeLeague; // 一场比赛所属的联赛
		String strOrderLeague;// 用户选择的联赛集合中的一条

		for (int i = 0; i < leagueNameList.size(); i++) {
			strItmeLeague = sportteryBasketballAgainstInfo.getSimpleLeague().replaceAll("\\s", Config.NULLMARK);
			strOrderLeague = leagueNameList.get(i).replaceAll("\\s", Config.NULLMARK);
			if (strItmeLeague.equals(strOrderLeague)) {
				b = true;
				break;
			}
		}
		return b;
	}
}
